package jmars.mobile.misc;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;

import jmars.mobile.common.Sha;

public class ExtractLACFromBase64 {

	private static String out="E:\\BaiduYunDownload\\afterprocess\\lac.txt";
	private static String in="E:\\BaiduYunDownload\\data\\jmars.mobile.worker.EntropyTrafficTotalHourly_LAC_CI-outputD.txt";
	public static void main(String[] args) throws IOException{
		String row;
		String[] cols;
		FileWriter resultWriter;
		resultWriter = new FileWriter(out);
		File fin = new File(in);
		FileInputStream fis = new FileInputStream(fin);
		BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
		int headercount=0;
		resultWriter.write("%lac_hash,lac,ci\r\n");
		String tmp;
		while((row=reader.readLine())!=null){
			if(headercount<=5){
				headercount++;
				continue;
			}
			cols=row.split(",");
//			resultWriter.write(row.replaceFirst(cols[0].substring(40), "")+"\r\n");
			tmp=Sha.getFromBASE64(cols[0].substring(40)).replaceAll("\\$_\\$\\$_\\$", ",").replaceAll("\\$_\\$", "");
			resultWriter.write(cols[0].substring(0,40)+","+tmp+"\r\n");
//			System.out.println(tmp);
		}
		fis.close();
		resultWriter.close();
		System.out.println("finished.");
	}
	

}
